/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int res = 0;
    int maxDepth(TreeNode* root) {
        getMaxDepth(root,1);
        return res;
    }
    void getMaxDepth(TreeNode* tree, int depth){
        if(!tree)return;
        res = max(res,depth);
        getMaxDepth(tree->left,depth+1);
        getMaxDepth(tree->right,depth+1);
    }
};